<?php
namespace app\admin\controller;
use think\Controller;

class Authali extends Controller
{
    public function getuser()
    {
        $code = $_REQUEST['auth_code'];
        import('alipay.aop.AopClient', EXTEND_PATH);
        import('alipay.aop.request.AlipaySystemOauthTokenRequest', EXTEND_PATH);
        import('alipay.aop.request.AlipayUserUserinfoShareRequest', EXTEND_PATH);
        $aop = new \AopClient;
        $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
        $aop->appId = "2019052065205188";
        $aop->rsaPrivateKey = 'MIIEpQIBAAKCAQEAlnemjJ0OSNt1SzGhSkdWtmK7S1FKSwpcRiCIfVF0ViP3ZAB8MlpFTdQ7Zq0mXbIRHU3V5HCsmJLtvuyws+QJY90BMGxlItKPXc+5ZnRqIJIaBd99qlCX/CNCZA4mmsocMmz/LT41QMv5SMB1PiBPJqQme/WiaBZlFcmCETU8e2n/YBlGj3GaDy5tWy9W6qHEUc/1H74LEDsQJn176rKCzEfAUwaZOv6eoElGzXfrgXmgvbXpuBvAY9TwQ0rK6YGMeO5fUM157Ti/4/cWIxVFUj06zi5aNgGNCrv6jxDZPG4l+sQeUay9xc4sClHI8YXw6jq6LJHdr8uif5BW6YhsqQIDAQABAoIBAH3+xynrwbBkhD1o26R1RDkJR8hz04AutsHKMECv2njfOSM1/Mm1KV9Ynj0GNKA0oXwmVzso1n4UWpyLWhPomaxTvdEskyuroX1umdMfHFcVwFC2qmXZgssRQ2DBMLZhE2duOedKthECPEYdUo+pQl4bCla2gz4hspeh2xZJu9Gi0ga3LHfPPFbm4P4V9yf60kAkr6CIHYJgK1j7ECfZmhj/FiS/MGk+X6ognPSTAAWaycDrCPfrTmMiYAScRZ8TOpTUW8AX+SIrnhVfEzRrw1qEc1Nhtd9aGY9SUfLQwwd6RB1wmzBSa4H55b316yjqUZGRBWvrE8/4Pl1vK8In5/kCgYEAx4NoUTyiWUVR/GdywThsW1FJ3j2Xz6OzFjMEkMuLOeAj88zk4cqalTBZzlNs/BLf40GmBTJuDooEfKNR7mjY2Cy8pfkr8Ez5r1RC8uU1y3+Dd2MXvSbwlu4l9LqAMD8XFuVSdSuezd1wh7/gDKuBz4JOEI4x0vUTGrmnIc4VcRMCgYEAwRFtSwzf+KsrdKbKGQqGRTVfZluwjirjZnXfco7VBj1ZoGBNcv5i7oS68FmAKUiA1SfZBlQxKMju4Uq73LOYfZ/z4irXCcd74mb7qpwi9/XmXEc/b09ZPoqfQNrGgMbw/jK+19cDqnR0jpmGbtneIMWmFAB3WVZXZXpxyjp0HtMCgYEAt6yEZvV5SNIGjmX2QWfeaZtGc/EkR6YfAvro4xxgCmIM9y/ULwJEmcAvjUFEfjQqJZ+UZghtRblONChvDxs7NpjI+8uO5eUXoI/kKpVVlwjHUSvK+PpWV7za+JiR1tjeOtfXt8L2qfOI25CLhV6HXTBLCfa+a8XvVpVABmEhYD0CgYEAisY++/omJzTKCJA2pic1ehuyFf4D+zyCtcw2L77RCiog+TEfmm+VpwKK6GY8w+/UguKgkXcE2t8LLa8tN6d0DaBiigfnB6V2u7bwYKLYU8lRqrSfuR+c82JqtBBNLJVS9jR9juGDRgttGG7r/VPm4UGQbcIkB3gTW+LWVdkMTHcCgYEArXyiBWXQN2yK9yK86/23GupMQ6jb6kGP0PjtMLBZ74W6n3GCQQ34Q9SzL4Ea2ZcWtHFoLmirjvQJAvq98lHCdbtUY62l7CT99PQxXw87+OEHeXWIeyhvLl9cIQtlS1E9HQydWIjGtpSGSE8FJG0TCWsYuzgTm3VmNbxE3CnTjWg=';
        $aop->format = "json";
        $aop->charset = "UTF-8";
        $aop->signType = "RSA2";
        $aop->alipayrsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwamELkZPcThxb5wg789OSjkkfbFcwlb8KavQ1TKdoa7ZR3w6QdzYLXkS/aqGgNjT0+WJm/yup+wzr7G/o7POY8PlUvaLofxOw/CiA8NLAki+hrmFZhfPUrV218u5cNKYaQx5PIbjpSxI/fwOPXIJ9ZV5LJUouA1EbGthrskiM/lbHHYonfwdr94b6I+e2HuiRMhvRgVI55a8tPMIdJvO+u4GQLLbtOlL0aZ+cOAKvz7T9eSMwvdzDs0IYRQgasKgyyVdvxOB0XaCfYPtQ8CC+CQs53b+EfX6A/WG+cgXYR75MVHzHWTP4Qg+EszEOxIfcrJkiBa4gd+Fs2wPp73HrQIDAQAB';
        $request = new \AlipaySystemOauthTokenRequest();
        $request->setGrantType('authorization_code');
        $request->setCode($code);
        $result = $aop->execute($request);
        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
        //获取access_token
        $user_id = $result->$responseNode->user_id;
        if($user_id){
            session('openid11', $user_id);
            $url2 =  "http://".$_SERVER['HTTP_HOST'];
            $aid = session('invite_code');
            $shop_id = session('shop_id');
            echo "<script> location.href=\"$url2/admin/Share/register?code=$aid&shop_id=$shop_id\"; </script>";
        }
    }
}
